package com.hele.sts.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.pub.ConnectDB;
import com.hele.sts.pub.SpringContextHolder;

public class QyajbDao {

	private static final Logger logger = LoggerFactory.getLogger(QyajbDao.class);
	
	  public static Qyajb load(String nbxh)
	  {
	    Connection conn = null;
	    PreparedStatement pstmt = null;
	    ResultSet rs = null;
	    String sql = null;
	    ConnectDB connsyb = null;
	    sql = "select * from da_qyajb where nbxh = ?";
	    logger.debug(sql);
	    Qyajb qyajb = null;
	    try
	    {
	      connsyb = SpringContextHolder.getBean(ConnectDB.class);
	      conn = connsyb.getConnection();
	      pstmt = conn.prepareStatement(sql);
	      pstmt.setString(1, nbxh);
	      rs = pstmt.executeQuery();
	      if (rs.next()) {
	    	  qyajb = rsToBean(rs);
	      }
	      return qyajb;
	    }
	    catch (SQLException e)
	    {
	      logger.info("db error", e);
	    }
	    finally
	    {
	      DbClose.freePreparedStatement(pstmt);
	      DbClose.freeConnection(conn);
	      DbClose.freeResultSet(rs);
	    }
	    
	    return null;
	  }

	private static Qyajb rsToBean(ResultSet rs) throws SQLException {
		Qyajb qyajb = new Qyajb();
		qyajb.setNbxh(rs.getString("nbxh"));
		qyajb.setQzh(rs.getString("qzh"));
		qyajb.setFlh(rs.getString("flh"));
		qyajb.setAjh(rs.getString("ajh"));
		qyajb.setJnys(rs.getString("jnys")==null?0:rs.getInt("jnys"));
		qyajb.setBgqx(rs.getString("bgqx"));
		qyajb.setQzrq(rs.getString("qzrq"));
		qyajb.setYh(rs.getString("yh"));
		qyajb.setJnqsmlbh(rs.getString("jnqsmlbh")==null?0:rs.getDouble("jnqsmlbh"));
		qyajb.setInqsmlbh(rs.getString("inqsmlbh")==null?0:rs.getDouble("inqsmlbh"));
		qyajb.setBz(rs.getString("bz"));
		qyajb.setTid(rs.getString("tid"));
		qyajb.setEpc(rs.getString("epc"));
		qyajb.setPosiNo(rs.getString("posi_no"));
		return qyajb;
	}
}
